package com.hnjowe.util;

import java.io.*;

import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.rtf.*;

public class AccessRTF {
	private DefaultStyledDocument dsd;  
	private RTFEditorKit rtf;  
	public String readRtf(File in) {
		String result = "";
		rtf=new RTFEditorKit();
		dsd = new DefaultStyledDocument();
		try {
			rtf.read(new FileInputStream(in), dsd, 0);
			result = new String(dsd.getText(0, dsd.getLength()));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (BadLocationException e) {
			e.printStackTrace();
		}
		return result;
	}
	public void writeRtf(File out) {
		try {
			rtf.write(new FileOutputStream(out), dsd, 0, dsd.getLength());
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (BadLocationException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		AccessRTF readRTF=new AccessRTF(); 
        System.out.println(readRTF.readRtf(new File("C:/leochen/P_WORKS/mjx/union/code/WebRoot/template/template001.rtf")));
    }  
}